package com.derbysoft.dswitch.adapter.ihg.web.action.admin.setting.rateplan;

import com.derbysoft.dswitch.adapter.ihg.common.domain.RatePlan;
import com.derbysoft.dswitch.adapter.ihg.common.repository.RatePlanRepository;
import com.derbysoft.dswitch.adapter.ihg.web.action.support.BaseAction;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;


public class DelAction extends BaseAction {
    @Autowired
    private RatePlanRepository ratePlanRepository;

    private String ratePlanCode;

    @Action("delete")
    public String execute() {
        if (StringUtils.isBlank(ratePlanCode)) {
            return LIST;
        }
        RatePlan ratePlan = ratePlanRepository.loadByCode(ratePlanCode);
        if (ratePlan != null) {
            ratePlanRepository.delete(ratePlan);
        }
        return LIST;
    }

    public String getRatePlanCode() {
        return ratePlanCode;
    }

    public void setRatePlanCode(String ratePlanCode) {
        this.ratePlanCode = ratePlanCode;
    }
}
